/**----------------------------------------
 * @description 系统相关工具类
 * @author      lxc
 * @file        SystemTool.ts
 * @Date        2022-05-05
 * @version     1.0.0
 * ----------------------------------------
 */

import { LogClass } from "../LogClass";

export class SystemTool extends LogClass {
    /**
     * 打印系统相关尺寸
     */
    printSysSizeInfo() {
        // 当前游戏窗口大小
        this.printLog(" 窗口大小 winsize.width : ", cc.winSize.width, " winsize.height : ", cc.winSize.height)

        let framesSize = cc.view.getFrameSize()
        this.printLog(" 视图边框 framesSize.width : ", framesSize.width, " framesize.height : ", framesSize.height)

        let canvasSize = cc.view.getCanvasSize()
        this.printLog(" canvas.width : ", canvasSize.width, " canvas.height : ", canvasSize.height)

        let visibleSize = cc.view.getVisibleSize()
        this.printLog(" 可见区域 visibleSize.width : ", visibleSize.width, " visibleSize.height : ", visibleSize.height)

        let designSize = cc.view.getDesignResolutionSize()
        this.printLog(" 设计SIZE designSize.width : ", designSize.width, " designSize.height : ", designSize.height)
    }
    /**
     * 适配多分辨率
     * canvas 固定宽高都不要勾选
     */
    adaptaionResoulution() {
        let frameSize = cc.view.getFrameSize();
        let designSize = cc.view.getDesignResolutionSize();
        if (frameSize.width / frameSize.height > designSize.width / designSize.height) {
            cc.Canvas.instance.fitHeight = true;
            cc.Canvas.instance.fitWidth = false;
        } else {
            cc.Canvas.instance.fitHeight = false;
            cc.Canvas.instance.fitWidth = true;
        }
    }

    private _backgroundScale = -1
    /**
     * 计算宽高比铺满背景图
     * @param backgroud 
     */
    backgroudFill(backgroud: cc.Node) {
        if (this._backgroundScale < 0) {
            let canvasSize = cc.view.getCanvasSize();
            let scaleW = canvasSize.width / backgroud.width
            let scaleH = canvasSize.height / backgroud.height
            this._backgroundScale = Math.max(scaleW, scaleH);
        }
        backgroud.setScale(this._backgroundScale);
    }
}